
-- var.extflags 标志位，永久标志
actor_extflags = {
	gave_exp_bead = 0, -- 是否已经领取经验灵珠
	gave_wing_gift = 1, -- 是否已经领取青铜礼包(翅膀) 880
	gave_stone_gift = 2, -- 是否已经领取青铜礼包(武魂) 888
	gave_bead_gift = 3, -- 是否已经领取青铜礼包(灵珠) 884	
}

-- var.days.dayflags 标志位，每日清0
actor_dayflags = {
	gave_pay_gift = 0, -- 是否已经领取每日充值大礼包
	exp_jade_quest1 = 1, -- 日常经验珠任务(使用10颗)
	exp_jade_quest2 = 2, -- 日常经验珠任务(使用20颗)
	exp_jade_quest3 = 3, -- 日常经验珠任务(使用30颗)
	enter_sbk = 4,		 -- 是否已进入过沙巴克场景
}

------------------------------

function get_extflags(sysarg, flag)
	if flag < 0 or flag > 31 then
		print("----error! get_extflags flag="..flag)
		return false
	end
	
	local var = Actor.getStaticVar(sysarg)
	if var.extflags == nil then return false end
	
	local f = System.getIntBit(var.extflags, flag)
	if (f ~= 0) then return true 
	else return false end
end

function set_extflags(sysarg, flag, true_or_no)
	if flag < 0 or flag > 31 then
		print("----error! set_extflags flag="..flag)
		return
	end
	
	local var = Actor.getStaticVar(sysarg)
	local extflags = var.extflags
	if extflags == nil then extflags = 0 end
	
	extflags = System.setIntBit(extflags, flag, true_or_no)
	var.extflags = extflags
end

function get_dayflags_from_var(var, flag)
	if flag < 0 or flag > 31 then
		print("----error! get_dayflags_from_var flag="..flag)
		return false
	end
	if not var.days then var.days = {} end
	if var.days.dayflags == nil then return false end
	
	local f = System.getIntBit(var.days.dayflags, flag)
	if (f ~= 0) then return true 
	else return false end
end

function get_dayflags(sysarg, flag)
	if flag < 0 or flag > 31 then
		print("----error! get_dayflags flag="..flag)
		return false
	end
	
	local var = Actor.getStaticVar(sysarg)
	if not var.days then var.days = {} end
	if var.days.dayflags == nil then return false end
	
	local f = System.getIntBit(var.days.dayflags, flag)
	if (f ~= 0) then return true 
	else return false end
end

function set_dayflags(sysarg, flag, true_or_no)
	if flag < 0 or flag > 31 then
		print("----error! set_dayflags flag="..flag)
		return
	end
	
	local var = Actor.getStaticVar(sysarg)
	if not var.days then var.days = {} end
	local dayflags = var.days.dayflags
	if dayflags == nil then dayflags = 0 end
	
	dayflags = System.setIntBit(dayflags, flag, true_or_no)
	var.days.dayflags = dayflags
end

--下发玩家标志
function SendActorExtflags(sysarg)
	local var = Actor.getStaticVar(sysarg)
	local extflags = var.extflags
	if extflags == nil then extflags = 0 end
	if not var.days then var.days = {} end
	local dayflags = var.days.dayflags
	if dayflags == nil then dayflags = 0 end
	
	local netPack = DataPack.allocPacket(sysarg, LogicCmd.miscSys.sysId, LogicCmd.miscSys.sub.sSendActorExtflags)	
	DataPack.writeUInt(netPack, extflags)
	DataPack.writeUInt(netPack, dayflags)
	DataPack.flush(netPack)
end

function DayQuest_ExpJade(sysarg)
	local level = Actor.getIntProperty(sysarg,PROP_CREATURE_LEVEL)
	if level < 68 then
		Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.zf198,68), ttFlyTip)
		return false
	end
	
	local var = Actor.getStaticVar(sysarg)
	
	local useTimes = var.jadeTime
	if useTimes == nil then useTimes = 0 end
	
	-------------------------------------------------------
	-- 第1次经验珠任务
	if useTimes < 10 then -- 还没有完成任务
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.zf679, ttFlyTip)
		return false
	end
	
	-- 领取第1次经验珠任务奖励
	if get_dayflags_from_var(var, actor_dayflags.exp_jade_quest1) == false then
		Actor.giveAward(sysarg,2,0,20000000,0,0,0,0,GameLog.cDayQuestExpJade,"ExpJadeQuest1")	
		set_dayflags(sysarg, actor_dayflags.exp_jade_quest1, true)
		
		local msg = string.format(Lang.ScriptTips.b002, Actor.getName(sysarg), 10, 2000)
		System.broadcastTipmsg(msg,2048)
		return true -- 返回true则刷新任务
	end
	
	-------------------------------------------------------
	-- 第2次经验珠任务
	if useTimes < 20 then -- 还没有完成任务
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.zf679, ttFlyTip)
		return false
	end
	
	-- 领取第2次经验珠任务奖励
	if get_dayflags_from_var(var, actor_dayflags.exp_jade_quest2) == false then
		Actor.giveAward(sysarg,2,0,30000000,0,0,0,0,GameLog.cDayQuestExpJade,"ExpJadeQuest2")	
		set_dayflags(sysarg, actor_dayflags.exp_jade_quest2, true)		
				
		local msg = string.format(Lang.ScriptTips.b002, Actor.getName(sysarg), 20, 3000)
		System.broadcastTipmsg(msg,2048)
		return true -- 返回true则刷新任务
	end
	
	-------------------------------------------------------
	-- 第3次经验珠任务
	if useTimes < 30 then -- 还没有完成任务
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.zf679, ttFlyTip)
		return false
	end
	
	-- 领取第3次经验珠任务奖励
	if get_dayflags_from_var(var, actor_dayflags.exp_jade_quest3) == false then
		Actor.giveAward(sysarg,2,0,40000000,0,0,0,0,GameLog.cDayQuestExpJade,"ExpJadeQuest3")	
		set_dayflags(sysarg, actor_dayflags.exp_jade_quest3, true)		
				
		local msg = string.format(Lang.ScriptTips.b002, Actor.getName(sysarg), 30, 4000)
		System.broadcastTipmsg(msg,2048)
		return true -- 返回true则刷新任务
	end
	-------------------------------------------------------
	
	-- 已经领过了
	Actor.sendTipmsg(sysarg, Lang.ScriptTips.zf620, ttFlyTip)
	return true -- 返回true则刷新任务
end

function DayQuest_ExpJadeWndTip(sysarg)
	local str = "1.经验珠可在商城购买；\n2.杀怪获得经验可聚入经验珠；\n3.双击集满的经验珠可获得经验；\n{color;FF7CFC00;※快速聚集经验地图：}{color;FFFF0000;经验副本、屠魔圣殿、富贵兽、挂机地图}"
	Actor.messageBox(sysarg,0,0,str, "关闭/CanleExpJadeWndTip", NULL, NULL, 0)
end

--关闭
function CanleExpJadeWndTip(sysarg)
	return nil
end